﻿using Microsoft.EntityFrameworkCore;

namespace orm.efcore.api.Entities
{
    public class CoreDbContext : DbContext
    {
        public CoreDbContext(DbContextOptions options) : base(options) 
        {
            // 关闭延迟加载
            ChangeTracker.LazyLoadingEnabled = false;
        }

        public virtual DbSet<Order> Order { get; set; }

        public virtual DbSet<OrderDetail> OrderDetail { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            // 更改默认跟踪行为：查询时不跟踪
            optionsBuilder.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
        }
    }
}
